package jalus.pojo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.google.appengine.api.users.User;
/**
 * 日志数据表
 * 
 *
 */
public class Post implements Serializable{

	private static final long serialVersionUID = 5870596576404951214L;
	private Long id;
    private String title;
    private Date date;
    private User author;
    private String content;
    
    private String url;
    private String sauthor;
    
    /**
     * 0. 非管理员不能查看，不能评论
     * 1. 普通Post
     * 2. Spin Post，可以评论
     * 3. Spin Post，不可评论
     */
    private Integer privilege;
    
    private Integer commented;
    
    private Date last_modify_date;
    private User last_modify_by;
    private List<String> tags;
    
    private Integer commentCount;
    
    public Post(){
    }
    
    public Post(Long id, User author, String title, Integer privilege, String content, Date date, List<String> tags) {
    	this.id = id;
        this.author = author;
        this.title = title;
        this.privilege = privilege;
        this.content = content;
        this.date = date;
        this.tags = tags;
        this.commented = 0;
    }

    public Long getId() {
        return id;
    }

    public User getAuthor() {
        return author;
    }

    public String getContent() {
        return content;
    }

    public Date getDate() {
        return date;
    }

    public void setId(Long id){
    	this.id = id;
    }
    
    public void setAuthor(User author) {
        this.author = author;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setDate(Date date) {
        this.date = date;
    }

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	public void setPrivilege(int privilege) {
		this.privilege = privilege;
	}

	public int getPrivilege() {
		return privilege;
	}

	public void setLast_modify_date(Date last_modify_date) {
		this.last_modify_date = last_modify_date;
	}

	public Date getLast_modify_date() {
		return last_modify_date;
	}

	public void setLast_modify_by(User last_modify_by) {
		this.last_modify_by = last_modify_by;
	}

	public User getLast_modify_by() {
		return last_modify_by;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public List<String> getTags() {
		return tags;
	}


	public Integer getCommentCount() {
	    return commentCount;
	}

	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUrl() {
		return url;
	}

	public void setSauthor(String sauthor) {
		this.sauthor = sauthor;
	}

	public String getSauthor() {
		return sauthor;
	}
	/**
	 * 是否在文章列表中显示
	 * @return
	 */
	public boolean isVisiable(){
		return this.privilege == 1;
	}
	/**
	 * 非管理员是否有权限查看
	 * @return
	 */
	public boolean isAuthorized(){
		return this.privilege == 0;
	}
	
	/**
	 * 是否开放评论
	 * @return
	 */
	public boolean isCommentEnabled(){
		return this.commented == 0 && this.privilege != 0;
	}
	
	public boolean isSpined(){
		return this.privilege == 2;
	}
}